/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Mob Crap for list     ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

mob
	Login()
		src.icon = 'status.dmi'

		if(src.client.IsTelnet())
			src.icon_state = "Telnet"

		else
			src.icon_state = src.client.Status

		..()


/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Client Variables      ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

client

	control_freak = CONTROL_FREAK_SKIN
	preload_rsc = 1

	var
		Grid_Color = "black"
		Font_Weight = "normal"

		list/Status = null

		list/Ignored = list()

		name = ""

		Inputted = 0
		Typing = 0
		Messages = 0
		IM_Windows = 0
		IM_ENABLE = 1
		First_Login = 1
		RADIO = 0
		CAM = 0
		MUTEO = 0

		ShowCodes = 0
		CodeShown = 0

		Kicked = 0
		DualKey = 0

		Colors = 1
		WhoSide = 0
		Max_Lines = 1000

		Name_Color = "000000"
		Text_Color = "000000"
		Output_Style = "MS Sans Serif"

		HOUR_Offset = 0
		MIN_Offset = 0
		SEC_Offset = 0

		default_cmd = ""

		//Profile

		User_Name = "Unknown"
		User_Gender = "Male"
		User_Age = "??"
		User_Image = "" // URL
		User_Location = ""
		User_Email = ""
		User_Contact = ""
		User_Messenger = ""
		Status_Type = "Available"
		Status_Message = ""
		Status_Color = AV_COLOR

		//Other
		Credits = 1000
		USER_LOADED = 0
		STATUS_CHANGED = 0
		WINDOW_LOCATION = "10,10"

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Client Procedures     ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

	proc/checkDualKey()
		for(var/client/C in Everyone)
			if(src.computer_id == C.computer_id)
				src.DualKey = TRUE
				System_UserMessage(src, "You're already logged in on another key.")
				del(src)


	New()

		src.UpdateArchive()

		if(checkBan(src.ckey))
			System_UserMessage(src, "You're banned, go away.")
			sleep(3)
			del(src)

		src.LoadMe()

		winset(src,"Main","pos=[WINDOW_LOCATION]")

		if(!src.TotalWon)
			TotalSpins = 0
			TotalWager = 0
			TotalWon = 0

		. = ..()


		// Normal User
		if(!IsTelnet())

			src.checkDualKey()
			if(!DualKey)
				name = key

				src<<output("[ConversationTopic]","Main.Topic")
				src<<Welcome

				System_WorldMessage("Welcome to The Saloon, [src.key]!")
				System_UserMessage(src, ConversationTopic)
				System_AdminMessage("<font size='0pt'>Aliases: [ReturnKeys(src.key)]</font>")

				if(src.ckey in Admins)
					src.verbs+=typesof(/client/Admin/verb)
					src.verbs+=typesof(/client/Mod/verb)
					src.Grid_Color = "#9966CC"
					src.Font_Weight = "bold"

				if(src.ckey in Moderators)
					src.verbs+=typesof(/client/Mod/verb)
					src.Font_Weight = "bold"

				spawn() GenerateCredits()
				CloseGames()

		// Telnet User
		else
			// Telnet user.
			name = copytext(key, findtext(key, "@"))
			mob.name = name
			System_WorldMessage("[src.name] has entered The Saloon!")
			System_AdminMessage("<font size='0pt'>Aliases: [ReturnKeys(src.key)]</font>")
			System_UserMessage(src, ConversationTopic)


		src.adjustInterface()

		// Chat lists

		Everyone+=src
		Available+=src
		Status = Available
		setStatus("Available")
		spawn() checkTypingStatus()

		LoadCasino()
		if(Credits == null)
			src.Credits = 1000
			src.SaveCasino()

		if(IM_ENABLE == null) IM_ENABLE = 1

		updateUsers()
		for(var/client/c in Everyone) if(c.ckey in Admins) c.adminUpdateQuick()

		if(First_Login != 0)
			src.browseAddress("http://dl.dropbox.com/u/16250107/Saloon/readme.html")
			First_Login = 0

		USER_LOADED = 1

	Del()
		if(USER_LOADED)
			// Save the user information
			src.SaveMe()

			// Remove their information from the userlist.
			if(src && !src.DualKey)
				if(Status) Status -= src
				Everyone-=src

			if(src.key in Banned || src.DualKey)
			else if(src.Kicked)	System_WorldMessage("[src.name] has been kicked.")
			else if(src.Status) System_WorldMessage("[src.name] has left The Saloon.")

			// Delete their showcode information
			if(fexists("ShowCode/[src.key].sav")) fdel("ShowCode/[src.key].sav")
			updateUsers()
			del(src.mob)

		for(var/client/c in Everyone) if(c.ckey in Admins) c.adminUpdateQuick()
		..()

	Click(mob/M, location, control, params)
		..()
		var/list/p = params2list(params)
		if(istype(M,/mob) && M.client)
			if("ctrl" in p) if(M.key!=src.key) Create_IM(src.key, M.key)
			else if("shift" in p)
				if(!(src.ckey in Admins)) return
				var/ID = ReturnKeyID(M.key)
				ViewID(ID)
			else loadProfile(M.client)


proc

	// Returns the client matching the string given if found.
	findTarget(string)
		for(var/client/C)
			if(C.key == string || C.ckey == string)
				return C;
		return null

	// Send a message to a specific client as a bot
	System_UserMessage(var/client/target, var/message as text)
		var/Time = target.getTime()
		target<<"<b>\[</b>[Time]<b>\] <font color='[html_encode(Bot_Color)]'>@Wench</font></b>: <font color='red'>[message]</font>"

obj
	cam
		icon = 'status.dmi'
		icon_state = "webcam"
		layer=MOB_LAYER+1
	note
		icon = 'status.dmi'
		icon_state = "music"
		layer=MOB_LAYER+1
	muted
		icon = 'status.dmi'
		icon_state = "muted"
		layer=MOB_LAYER+1